package com.yazif.vqa.task.chain;

import com.yazif.vqa.api.wechat.domain.Message;
import com.yazif.vqa.dao.RedisDao;
import com.yazif.vqa.task.AbstractTarget;
import com.yazif.vqa.task.Target;
import com.yazif.vqa.util.MessageUtils;
import com.yazif.vqa.util.RedisKeyUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ImageTarget extends AbstractTarget {

    @Resource
    private RedisDao redisDao;


    @Override
    public Message execute(Message message, Target target) {

        if ("IMAGE".equals(message.getMsgType())) {
            String user = message.getFromUserName();
            String key = RedisKeyUtil.getImageKey(user);
            redisDao.set(key, message.getPicUrl());
            Message send = MessageUtils.getBaseRecvMessage(message);
            send.setMsgType("TEXT");
            send.setContent("get, 图片已更新！");
            return send;
        }

        return target.execute(message);
    }

}
